home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / c2p_src / ver.c < prev   
C/C++ Source or Header  |  1999-01-01  |  3KB  |  89 lines

  1. /* :ts=4                                ver.c
  2.  *
  3.  *    ver - Version update util
  4.  *    Copyright (C) 1998 Gáti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  *
  22.  *
  23.  * usage:
  24.  *             filename        - basename of app.
  25.  *             none            - update date only
  26.  *             -r                - update rev
  27.  *             -v                - update ver
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include <time.h>
  34.  
  35. char fname[300];
  36. char vname[300];
  37. char vers[100];
  38. char revs[100];
  39. char copyright[]="Copyright © by Gáti Gergely";
  40.  
  41. int main(int argc, char **argv) {
  42.     FILE *f,*v;
  43.     time_t tval;
  44.     struct tm *lt;
  45.     int ver,rev;
  46.     int day,month,year;
  47.     int hour,minute;
  48.  
  49.     if(argc<2) return(-1);
  50.     strcpy(fname,argv[1]);
  51.     strcat(fname,"_ver.h");
  52.     strcpy(vname,argv[1]);
  53.     strcat(vname,"_ver.data");
  54.     v=fopen(vname,"rb");    
  55.     if(v!=NULL) {
  56.         fgets(vers,100,v);
  57.         ver=atoi(vers);
  58.         fgets(revs,100,v);
  59.         rev=atoi(revs);
  60.         fclose(v);
  61.     } else rev=ver=0;
  62.  
  63.     time(&tval);
  64.     lt=localtime(&tval);
  65.  
  66.     if(argc>2) {
  67.         if(strcmp(argv[2],"-r")==0) rev++;
  68.         if(strcmp(argv[2],"-v")==0) { ver++; rev=0; }
  69.     }
  70.  
  71.     v=fopen(vname,"wb");
  72.     if(v==NULL) return(-1);
  73.     fprintf(v,"%d\n%d\n",ver,rev);
  74.     fclose(v);
  75.  
  76.     f=fopen(fname,"wb");
  77.     if(f==NULL) return(-1);
  78.  
  79.     fprintf(f,"/* %s\n * %s version file\n",fname,argv[1]);
  80.     fprintf(f," *\n * Created by ver utility\n */\n\n");
  81.     fprintf(f,"#define VERSION         %d\n",ver);
  82.     fprintf(f,"#define REVISION        %d\n",rev);
  83.     fprintf(f,"#define DATE            \"%d.%d.%d\"\n",lt->tm_mday,lt->tm_mon+1,lt->tm_year);
  84.     fprintf(f,"#define VERS            \"%s %d.%d\"\n",argv[1],ver,rev);
  85.     fprintf(f,"#define VSTRING         \"%s %d.%d (%d.%d.%d)\\r\\n\"\n",argv[1],ver,rev,lt->tm_mday,lt->tm_mon+1,lt->tm_year);
  86.     fprintf(f,"#define VERSTAG         \"\\0$VER: %s %d.%d (%d.%d.%d) %s\"\n",argv[1],ver,rev,lt->tm_mday,lt->tm_mon+1,lt->tm_year,copyright);
  87.     fclose(f);
  88. }
  89.